package com.jinyi.wwdeng.analysis

import com.jinyi.base.base.BaseApplication
import com.jinyi.wwdeng.AppConfigs
import com.zhi.analysis.AnalysisBuilder
import com.zhi.analysis.AnalyticsUtil
import com.zhi.syc.data.ASSycBuilder
import com.zhi.syc.data.ASSycManager

/**
 * TODO: Analysis Lib 初始化时机
 */
object TestAnalysisInit {

    /**
     * TODO: APP启动时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtAppLaunch() {
        AnalysisBuilder.product = AppConfigs.AppName
        AnalysisBuilder.appVersion = "1"
        AnalysisBuilder.appPckName = "包名"

        AnalysisBuilder.aesKey = "vnLO7conqXpSLy6V"
        AnalysisBuilder.aesIv = "z5BEJPFcJplZzxxd"

        AnalysisBuilder.host = "http://159.138.165.72"
        AnalysisBuilder.zone = ""
        AnalysisBuilder.pathCommon = "/bnE2fc87ar6M97nBg82Q"

        AnalysisBuilder.pathGoogleInstall = "/DJk8cjznUm10N1PBgRVS6g"
        AnalysisBuilder.pathAdjustInstall = "/a19JYDMieo0NTMhpPSsSzyg"
        AnalysisBuilder.pathFacebookInstall = "/Ig7IaR5FnE9TzBh5I0fDw"

        AnalyticsUtil.init(BaseApplication.application)
    }

    /**
     * TODO: 成功获取地区转发路径时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtZoneSuccess() {
        AnalysisBuilder.zone = AppConfigs.getSPString(AppConfigs.SP_KEY.SP_HENECREDIT_TIMEZONE)
        AnalyticsUtil.init(BaseApplication.application)
    }

    /**
     * TODO: 成功登录时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtLoginSuccess() {
        AnalysisBuilder.token = AppConfigs.getSPString(AppConfigs.SP_KEY.SP_HENECREDIT_TOKEN)
        AnalysisBuilder.userId = AppConfigs.getSPString(AppConfigs.SP_KEY.SP_HENECREDIT_USERID)
        AnalyticsUtil.init(BaseApplication.application)
    }
}

/**
 * TODO: Analysis Lib 打点时机
 */
object TestAnalysisAddEvent {

    /**
     * TODO: 在调用登录接口，并成功返回时，如果 type=="REGISTER"，则调用注册事件打点
     */
    fun addRegisterEvent() {
        AnalyticsUtil.addRegisterEvent()
    }

    /**
     * TODO: 在调用提交贷款申请接口，并成功返回时，则调用申请事件打点
     */
    fun addApplyEvent() {
        AnalyticsUtil.addApplyEvent()
    }
}

/**
 * TODO: Data Lib 初始化时机
 */
object TestDataLibInit {

    /**
     * TODO: 成功获取地区转发路径时，初始化一下 data lib
     */
    fun initDataLibAtZoneSuccess() {
        ASSycBuilder.aesKey = "vnLO7conqXpSLy6V"
        ASSycBuilder.aesIv = "z5BEJPFcJplZzxxd"

        ASSycBuilder.product = AppConfigs.AppName
        ASSycBuilder.appid = AppConfigs.AppName

        ASSycBuilder.advertId = AnalyticsUtil.getAdId()
        ASSycBuilder.androidId = AnalyticsUtil.getAndroidId()

        ASSycBuilder.host = "http://159.138.165.72"
        ASSycBuilder.zone = AppConfigs.getSPString(AppConfigs.SP_KEY.SP_HENECREDIT_TIMEZONE)
        ASSycBuilder.pathCommon = "/bnE2fc87ar6M97nBg82Q"
        ASSycBuilder.pathApl = "/YBB74hRWw4xU6rCozZwwJA"
        ASSycBuilder.pathMag = "/a4nWmyE0MVpWzg6FMKSuUA"
        ASSycBuilder.pathDie = "/a0WPKOtBzBiKYpEWgrAbsQ"
        ASSycBuilder.pathBty = "/LTqdIt4jAUcdF4w6J5cw"
        ASSycBuilder.pathHdw = "/FITHwfn5DZh3MfD3M5jw"
        ASSycBuilder.pathContat = "/jyCUAElNCp1siECCLbFUkg"
        ASSycBuilder.pathSto = "/inZNsLflaEWU87wQbcdzrg"
        ASSycBuilder.pathNtw = "/mJC9povXIax3JBQDMMs5hQ"
        ASSycBuilder.pathCal = "/vthVCLIdCqkIWcNrjtNtNw"

        ASSycManager.init(BaseApplication.application)
    }
}

/**
 * TODO: Data Lib 调用时机
 */
object TestDataLibInvoke {

    /**
     * TODO: 在首页每次点击申请时（在已登录的前提下），调用一下 data lib 的上报
     */
    fun sycData() {
        val token = AppConfigs.getSPString(AppConfigs.SP_KEY.SP_HENECREDIT_TOKEN)
        ASSycBuilder.advertId = AnalyticsUtil.getAdId()
        ASSycBuilder.androidId = AnalyticsUtil.getAndroidId()

        ASSycManager.syncData(token = token) {
            // 当前业务可忽略这个回调
        }
    }

}